﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace QLCV
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void Reload()
        {
            if (GolbalSettings.CurrentUser.IsAdmin)
            {
                mnuDangNhap.Enabled = false;
                mnuDangXuat.Enabled = true;
                mnuTaiKhoan.Enabled = true;
                mnuSuaDen.Enabled = true;
                mnuSuaDi.Enabled = true;
                mnuThemDen.Enabled = true;
                mnuThemDi.Enabled = true;
                mnuThongKeDen.Enabled = true;
                mnuThongKeDi.Enabled = true;
                mnuCanBo.Enabled = true;

                btnDangNhap.Enabled = false;
                btnDangXuat.Enabled = true;
                btnSuaCongVanDen.Enabled = true;
                btnSuaCongVanDi.Enabled = true;
                btnTaiKhoan.Enabled = true;
                btnThemCongVanDen.Enabled = true;
                btnThemCongVanDi.Enabled = true;
                btnThongKeDen.Enabled = true;
                btnThongKeDi.Enabled = true;
            }
            else
            {
                mnuDangNhap.Enabled = true;
                mnuDangXuat.Enabled = false;
                mnuTaiKhoan.Enabled = false;
                mnuSuaDen.Enabled = false;
                mnuSuaDi.Enabled = false;
                mnuThemDen.Enabled = false;
                mnuThemDi.Enabled = false;
                mnuThongKeDen.Enabled = false;
                mnuThongKeDi.Enabled = false;
                mnuCanBo.Enabled = false;

                btnDangNhap.Enabled = true;
                btnDangXuat.Enabled = false;
                btnSuaCongVanDen.Enabled = false;
                btnSuaCongVanDi.Enabled = false;
                btnTaiKhoan.Enabled = false;
                btnThemCongVanDen.Enabled = false;
                btnThemCongVanDi.Enabled = false;
                btnThongKeDen.Enabled = false;
                btnThongKeDi.Enabled = false;
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            GolbalSettings.CurrentUser = new TaiKhoanDTO();

            //////////////////////////////////////
            //  testing

            GolbalSettings.CurrentUser.Username = "vpd";
            GolbalSettings.CurrentUser.IsAdmin = true;

            //////////////////////////////////////



            Reload();
            axShockwaveFlash1.Movie = Application.StartupPath + "\\khtn.swf";
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            frmDangNhap frmDNhap = new frmDangNhap();
            frmDNhap.ShowDialog();
            Reload();
        }

        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            GolbalSettings.CurrentUser = new TaiKhoanDTO();
            Reload();
            MessageBox.Show("Đã đăng xuất!" + Environment.NewLine + Environment.NewLine + "Bạn chỉ có quyền xem dữ liệu khi chưa đăng nhập.", "Da dang xuat", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }

        private void btnTaiKhoan_Click(object sender, EventArgs e)
        {
            frmSuaMatKhau frm = new frmSuaMatKhau();
            frm.ShowDialog();            
        }

        private void mnuThemCanBo_Click(object sender, EventArgs e)
        {
            frmCanBo frm = new frmCanBo();
            frm.ShowDialog();
        }

        private void mnuThemLoaiCongVanDen_Click(object sender, EventArgs e)
        {
            frmLoaiDen frm = new frmLoaiDen();
            frm.ShowDialog();
        }

        private void mnuThemLoaiCongVanDi_Click(object sender, EventArgs e)
        {
            frmLoaiDi frm = new frmLoaiDi();
            frm.ShowDialog();
        }

        private void mnuThemNoiNhan_Click(object sender, EventArgs e)
        {
            frmNoiNhan frm = new frmNoiNhan();
            frm.ShowDialog();
        }

        private void mnuThemDonVi_Click(object sender, EventArgs e)
        {
            frmDonVi frm = new frmDonVi();
            frm.ShowDialog();
        }

        private void btnThemCongVanDen_Click(object sender, EventArgs e)
        {
            frmThemDen frm = new frmThemDen();
            frm.ShowDialog();
        }

        private void btnTraCuuDen_Click(object sender, EventArgs e)
        {
            frmTraCuuDen frm = new frmTraCuuDen();
            frm.ShowDialog();
        }

        private void btnThongKeDen_Click(object sender, EventArgs e)
        {
            frmThongKeDen frm = new frmThongKeDen();
            frm.ShowDialog();
        }

        private void btnThemCongVanDi_Click(object sender, EventArgs e)
        {
            frmThemDi frm = new frmThemDi();
            frm.ShowDialog();
        }

        private void btnTraCuuDi_Click(object sender, EventArgs e)
        {
            frmTraCuuDi frm = new frmTraCuuDi();
            frm.ShowDialog();
        }

        private void btnThongKeDi_Click(object sender, EventArgs e)
        {
            frmThongKeDi frm = new frmThongKeDi();
            frm.ShowDialog();
        }

        private void mnuThongTin_Click(object sender, EventArgs e)
        {
            frmThongTin frm = new frmThongTin();
            frm.ShowDialog();
        }
  
    }
}
